init()
{
	self thread onPlayerSpawn();
}
onPlayerSpawn()
{
	self endon("disconnect");
	self endon("killed_player");
	self endon("stop_afkmonitor");
	
	org_spawnpt = spawn("script_origin", self.origin);	//Mark spawn point
	
	moved = false;
	count = 0;
	
	gametype = getcvar("g_gametype");

	for(;;)
	{
		moved = distance(org_spawnpt.origin, self.origin) > 12;

		if(moved) 
		{
			org_spawnpt delete();
			self notify("stop_afkmonitor");
			break;
		}
		
		if(gametype == "vip" && isDefined(self.isvip))
		{
			if(self.isvip)
			{
				if(count >= 15)
				{
					// Remove VIP and Select a new One.
					self.vip_credit = 0;
					self maps\mp\gametypes\vip::UnsetVIP();
					
					level thread maps\mp\gametypes\vip::SelectVIP(self.pers["team"]);
				
					org_spawnpt delete();
					self suicide();		//No score change for AFK kill
					self.score++;
					
					if(isDefined(self.pers["score"]))
						self.pers["score"] = self.score;
					self.deaths--;
					
					if(isDefined(self.pers["deaths"]))
						self.pers["deaths"] = self.deaths;
					
					self notify("stop_afkmonitor");
					break;
				}
			}
		}
		
		if(level.kill_afks_time == count) 
		{
			org_spawnpt delete();
			self suicide();		//No score change for AFK kill
			self.score++;
			
			if(isDefined(self.pers["score"]))
				self.pers["score"] = self.score;
			self.deaths--;
			
			if(isDefined(self.pers["deaths"]))
				self.pers["deaths"] = self.deaths;
			
			self notify("stop_afkmonitor");
			break;
		}
		count++;
		wait 1;
	}
}